package com.yanq.liancar.activity;
/*
 *  @创建者     Administrator
 *  @创建时间   2018/11/29  16:44
 *  @描述       ${TODO}
 */


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.gyf.barlibrary.ImmersionBar;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.vondear.rxtool.RxSPTool;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.bean.BaseBean;
import com.yanq.liancar.bean.UserBean;
import com.yanq.liancar.url.Config;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ProtocolDetaileActivity extends BaseToolbarActivity {
    @BindView(R.id.tv_qianyue)
    TextView tvQianyue;
    @BindView(R.id.webView)
    WebView webView;


    private String content;
    private int type;
    private String version;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_protocoldetaile);
        ButterKnife.bind(this);
        ImmersionBar.with(this).statusBarDarkFont(true).statusBarColor(R.color.white).init();

        mTvTitle.setText(getIntent().getStringExtra("name"));
        content=getIntent().getStringExtra("content");
        type=getIntent().getIntExtra("type",0);
        version=getIntent().getStringExtra("version");

        String js = "<script type=\"text/javascript\">"+
                "var imgs = document.getElementsByTagName('img');" + // 找到img标签
                "for(var i = 0; i<imgs.length; i++){" + // 逐个改变
                "imgs[i].style.width = '100%';" + // 宽度改为100%
                "imgs[i].style.height = 'auto';" +
                "}" + "</script>";
        webView.loadDataWithBaseURL(null,content+js,  "text/html", "UTF-8", null);
    }

    @OnClick(R.id.tv_qianyue)
    public void onViewClicked() {
        OkGo.<String>post(Config.s + "llc/api/ProtocolController/signProtocol")
                .tag(this)
                .params("token", UserBean.getbToken(mContext))
                .params("type", type)
                .params("protocol_version",version )
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        BaseBean bean = gson.fromJson(response.body(), BaseBean.class);
                        if (bean.isIsSuccess()) {
                            finish();
                            Toast.makeText(ProtocolDetaileActivity.this,"" + bean.getOutputMessage() , Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(ProtocolDetaileActivity.this, "" + bean.getOutputMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }
}
